using System;
using System.Collections;
using System.Web;
using Sedna.Core;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;
using Sedna.UI.Access;
using log4net;

namespace Sedna.UI.Access
{
	/// <summary>
	/// used for login check. if login is failed, in which case the LoginException is thrown by 
	/// the corresponding action
	/// a request is redirected to a login page once again at the same time cleaning 
	/// the contents of username and password fields.
	/// This handler also swtiches on the login error message indication.
	/// </summary>
	public class LoginExceptionHandler : AbstractExceptionHandler
	{
		private ILog log = LogManager.GetLogger(typeof(LoginExceptionHandler));

		public override Type ExceptionType
		{
			get { return typeof(LoginException); }
			set {throw new NotSupportedException("only LoginException type is supported");}
		}

		public override IActionResult HandleException(IExecutionContext executionContext, Exception exception)
		{
			log.Warn("login exception", exception);

            executionContext.SetPropertyValue("ec['loginUser.Username']", null);
            executionContext.SetPropertyValue("ec['loginUser.Password']", null);

			executionContext["login.errorlabel.visible"] = true;
								
			
			return new ActionResult(successStatus);
		}
	}
}
